﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Configuration;
using CPPEI.Coolzon.Configuration.Client;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Event.UI;
using CPPEI.Coolzon.Service.Contract;
using CPPEI.Coolzon.ServiceProxy;
using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;

namespace Coolvis.UI.Theme.Console
{
    /// <summary>
    /// 主题定义信息
    /// </summary>
    public class ThemeInfo
    {
        /// <summary>
        /// 主题名称，唯一标识
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 主题描述名称
        /// </summary>
        public string Caption { get; set; }

        /// <summary>
        /// 主题入口程序完成名称
        /// </summary>
        public string Class { get; set; }

        /// <summary>
        /// 主题预览文件路径
        /// </summary>
        public string PreviewImage { get; set; }

        /// <summary>
        /// 主题程序集名称
        /// </summary>
        public string Assembly { get; set; }
    }

    /// <summary>
    /// 主题管理类，用于获取主题相关配置信息
    /// </summary>
    public static class ThemeManager
    {
        /// <summary>
        /// 所有主题列表
        /// </summary>
        private static List<ThemeInfo> _themeInfoList;

        /// <summary>
        /// 当前主题名称
        /// </summary>
        private static string _currentThemeName;

        /// <summary>
        /// 当前主题信息
        /// </summary>
        private static ThemeInfo _currentThemeInfo;

        private static ITheme _currentTheme;

        /// <summary>
        /// 初始化配置信息,此方法在程序启动时调用，不允许调用多次
        /// </summary>
        /// <param name="configFilePath"></param>
        /// <exception cref="">可出异常</exception>
        public static void Init(string configFilePath)
        {
            if (_themeInfoList != null)
            {
                throw new Exception("引用程序主题配置文件只能初始化一次,不允许重复调用!");
            }
            //主题列表中是否含有当前主题
            bool IsHasCurrentTheme = false;
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(configFilePath);
            if (xmlDocument != null)
            {
                XmlNode xmlRoot = xmlDocument.SelectSingleNode("//Config");
                if (xmlRoot != null)
                {
                    XmlNode xmlCurrent = xmlRoot.SelectSingleNode("./Current");
                    if (xmlCurrent != null)
                    {
                        _currentThemeName = xmlCurrent.InnerText;
                    }

                    XmlNode xmlThemeList = xmlRoot.SelectSingleNode("./Theme-List");
                    if (xmlThemeList != null)
                    {
                        XmlNodeList xmlThemes = xmlThemeList.SelectNodes("./Theme");
                        if (xmlThemes != null && xmlThemes.Count > 0)
                        {
                            _themeInfoList = new List<ThemeInfo>();
                            foreach (XmlNode xmlTheme in xmlThemes)
                            {
                                ThemeInfo themeInfo = new ThemeInfo();
                                themeInfo.Name = (xmlTheme as XmlElement).GetAttribute("Name");
                                themeInfo.Caption = (xmlTheme as XmlElement).GetAttribute("Caption");
                                themeInfo.PreviewImage = (xmlTheme as XmlElement).GetAttribute("PreviewImage");
                                themeInfo.Class = (xmlTheme as XmlElement).GetAttribute("Class");
                                themeInfo.Assembly = (xmlTheme as XmlElement).GetAttribute("Assembly");
                                if (_currentThemeName.Equals(themeInfo.Name))
                                {
                                    IsHasCurrentTheme = true;
                                    _currentThemeInfo = themeInfo;
                                    Assembly assembly = Assembly.Load(themeInfo.Assembly);
                                    _currentTheme = (ITheme)assembly.CreateInstance(themeInfo.Class);
                                    if (_currentTheme == null)
                                    {
                                        throw new Exception("未能创建当前主题" + themeInfo.Class + "的实例。");
                                    }
                                }
                                _themeInfoList.Add(themeInfo);
                            }
                        }
                    }
                }
            }
            if (!IsHasCurrentTheme)
            {
                throw new Exception("当前主题不存在于主题列表中");
            }
        }

        /// <summary>
        /// 获取当前使用的主题信息
        /// </summary>
        /// <returns></returns>
        public static ThemeInfo GetCurrentTheme()
        {
            return _currentThemeInfo;
        }

        /// <summary>
        /// 获取所有定义的主题
        /// </summary>
        /// <returns></returns>
        public static List<ThemeInfo> GetAllThemes()
        {
            return _themeInfoList;
        }

        /// <summary>
        /// 获取当前主题实例
        /// </summary>
        /// <returns></returns>
        public static ITheme GetCurrentThemeInst()
        {
            return _currentTheme;
        }

        /// <summary>
        /// 创建主题实例
        /// </summary>
        /// <param name="themeInfo"></param>
        /// <returns></returns>
        public static ITheme CreateThemeInstance(ThemeInfo themeInfo)
        {
            return _currentTheme;
        }
    }

    public class Constant
    {
        /// <summary>
        /// 导航事件名称
        /// </summary>
        public static class NavEventNames
        {
            public const string ShowSelectScenePanel = "SSSP";
            public const string ShowSysFunctionPanel = "SSFP";
        }
    }

    /// <summary>
    /// 控制端的主题接口
    /// </summary>
    public interface ITheme
    {
        /// <summary>
        /// 获得主界面实例
        /// </summary>
        /// <returns></returns>
        IMainView GetMainView();

        /// <summary>
        /// 获取方案选择界面
        /// </summary>
        /// <param name="currentSolutionName"></param>
        /// <param name="isSwitchSolution"></param>
        /// <param name="isCanBeBack"></param>
        /// <returns></returns>
        CPPEI.Coolzon.UI.View CreateSelectSolutionView(string currentSolutionName, bool isSwitchSolution, bool isCanBeBack);

        /// <summary>
        /// 创建方案加载界面
        /// </summary>
        /// <param name="solution"></param>
        /// <param name="solutionFile"></param>
        /// <param name="solutionDirectory"></param>
        /// <returns></returns>
        CPPEI.Coolzon.UI.View CreateLoadingView(string solution, string solutionFile, string solutionDirectory);

        /// <summary>
        /// 获取登录页面
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        CPPEI.Coolzon.UI.View CreateLoginView(string account, string password);
    }

    /// <summary>
    /// 主界面
    /// </summary>
    public interface IMainView
    {
    }

    public interface ISelectSolutionView
    {
        /// <summary>
        /// 是否是新建的控制域，在用户点击方案时会向服务器提出创建一个控制域的请求，
        /// 但是如果服务器上已经存在了控制域，那么不会创建信息的，此值为false，
        /// 如果创建了新的控制域，此值为true
        /// </summary>
        bool IsNewDomain { get; }
        string SelectedSolutionName { get; }
    }

    public interface ILoadingView
    {
        event CPPEI.Coolzon.UI.Views.LoadingView.LoadSolutionError LoadSolutionErrorEvent;
    }

    #region views
    /// <summary>
    /// 用于做登录验证
    /// </summary>
    public class BaseLoginView : CPPEI.Coolzon.UI.View, INotifyPropertyChanged
    {
        /// <summary>
        /// 登陆类型
        /// </summary>
        public string SolutionSelectionMode { get; set; }

        private bool _isBusy4Login;
        /// <summary>
        /// 正在执行登录操作
        /// </summary>
        public bool IsBusy4Login
        {
            get
            {
                return _isBusy4Login;
            }
            set
            {
                if (_isBusy4Login != value)
                {
                    _isBusy4Login = value;
                    RaisePropertyChanged("IsBusy4Login");
                }
            }
        }

        public BaseLoginView()
        {
            CPPEI.Coolzon.Event.NCL.NCLEventBus.Register(this);
            IsBusy4Login = false;
        }

        protected override void OnActive()
        {
            base.OnActive();

            // 如果有打开的方案信息，需要再这里释放占用的资源
            // 回收资源
            if (UIContext.Current.RenderView != null)
            {
                // 1.去除RenderView里的所有组件的引用
                this.Dispatcher.Invoke(() =>
                {
                    (UIContext.Current.RenderView as RenderView).ClearAllParts();
                });
                // 2.去除组件创建缓存中的组件引用
                PartInstanceCache.ClearAllParts();
            }
        }

        protected override void OnDeactive()
        {
            NCLEventBus.Unregister(this);

            base.OnDeactive();
        }

        protected override void OnClose()
        {
            NCLEventBus.Unregister(this);
            base.OnClose();
        }

        /// <summary>
        /// 点击登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DoActionLogin(string account, string password)
        {
            if (string.IsNullOrEmpty(account))
            {
                return;
            }
            // 登录到系统
            // 构造登录请求
            NCLLoginEvent @event = new NCLLoginEvent();
            @event.Sender = this;
            @event.StartupPath = UIContext.Current.AppStartupPath;
            @event.AppType = UIContext.Current.AppType;
            @event.AppVersion = UIContext.Current.AppVersion;
            @event.OSVersion = UIContext.Current.OSVersion;
            @event.DotNetVersion = UIContext.Current.DotNetVersion;
            @event.UserAccount = account;
            @event.SolutionSelectionMode = SolutionSelectionMode;
            @event.UserPassword = password;

            NCLEventBus.PublishAsync(@event);
        }

        public void DoActionCancel()
        {
            //GC.Collect();
            NCLEventBus.Unregister(this);
            this.Cancel();
            Application.Current.Shutdown();
        }

        #region NCL Event

        [Subscribe]
        public void OnReceiveNCLLoginEventEvent(NCLLoginEvent @event)
        {
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (@event.State == NCLEventState.Failure)
                {
                    System.Windows.MessageBox.Show("登录失败，出现错误。",
                        "错误",
                        System.Windows.MessageBoxButton.OK,
                        System.Windows.MessageBoxImage.Error);
                }
                else if (@event.State == NCLEventState.Finished)
                {
                    // 登录成功
                    UIContext.Current.UserAccount = @event.Result.UserAccount;
                    UIContext.Current.UserName = @event.Result.UserName;
                    UIContext.Current.UserIdentity = @event.Result.UserIdentity;
                    this.Submit();
                }
            }));
        }
        #endregion

        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <summary>
    /// 登录页面的逻辑
    /// </summary>
    public class LoginViewLogic : INotifyPropertyChanged
    {
        /// <summary>
        /// 登陆类型
        /// </summary>
        public string SolutionSelectionMode { get; set; }

        private bool _isBusy4Login;
        /// <summary>
        /// 正在执行登录操作
        /// </summary>
        public bool IsBusy4Login
        {
            get
            {
                return _isBusy4Login;
            }
            set
            {
                if (_isBusy4Login != value)
                {
                    _isBusy4Login = value;
                    RaisePropertyChanged("IsBusy4Login");
                }
            }
        }

        private View _view;

        public void Init(View view)
        {
            CPPEI.Coolzon.Event.NCL.NCLEventBus.Register(this);
            IsBusy4Login = false;
            _view = view;
        }

        public void Active()
        {
            // 如果有打开的方案信息，需要再这里释放占用的资源
            // 回收资源
            if (UIContext.Current.RenderView != null)
            {
                // 1.去除RenderView里的所有组件的引用
                _view.Dispatcher.Invoke(() =>
                {
                    (UIContext.Current.RenderView as RenderView).ClearAllParts();
                });
                // 2.去除组件创建缓存中的组件引用
                PartInstanceCache.ClearAllParts();
            }
        }

        public void Deactive()
        {
            NCLEventBus.Unregister(this);
        }

        public void Close()
        {
            NCLEventBus.Unregister(this);
        }

        /// <summary>
        /// 点击登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DoActionLogin(string account, string password)
        {
            if (string.IsNullOrEmpty(account))
            {
                return;
            }
            // 登录到系统
            // 构造登录请求
            NCLLoginEvent @event = new NCLLoginEvent();
            @event.Sender = this;
            @event.StartupPath = UIContext.Current.AppStartupPath;
            @event.AppType = UIContext.Current.AppType;
            @event.AppVersion = UIContext.Current.AppVersion;
            @event.OSVersion = UIContext.Current.OSVersion;
            @event.DotNetVersion = UIContext.Current.DotNetVersion;
            @event.UserAccount = account;
            @event.SolutionSelectionMode = SolutionSelectionMode;
            @event.UserPassword = password;

            NCLEventBus.PublishAsync(@event);
        }

        public void DoActionCancel()
        {
            //GC.Collect();
            NCLEventBus.Unregister(this);
            _view.Cancel();
        }

        #region NCL Event

        [Subscribe]
        public void OnReceiveNCLLoginEventEvent(NCLLoginEvent @event)
        {
            _view.Dispatcher.BeginInvoke(new Action(() =>
            {
                if (@event.State == NCLEventState.Failure)
                {
                    System.Windows.MessageBox.Show("登录失败，出现错误。",
                        "错误",
                        System.Windows.MessageBoxButton.OK,
                        System.Windows.MessageBoxImage.Error);
                }
                else if (@event.State == NCLEventState.Finished)
                {
                    // 登录成功
                    UIContext.Current.UserAccount = @event.Result.UserAccount;
                    UIContext.Current.UserName = @event.Result.UserName;
                    UIContext.Current.UserIdentity = @event.Result.UserIdentity;
                    _view.Submit();
                }
            }));
        }
        #endregion

        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    /// <summary>
    /// 选择方案视图逻辑
    /// </summary>
    public class SelectSolutionViewLogic : INotifyPropertyChanged
    {
        private string _preSolutionName;
        public string SelectedSolutionName { get; private set; }

        /// <summary>
        /// 是否是切换方案
        /// </summary>
        private bool _isSwitchSolution;

        /// <summary>
        /// 是否是新建的控制域，在用户点击方案时会向服务器提出创建一个控制域的请求，
        /// 但是如果服务器上已经存在了控制域，那么不会创建信息的，此值为false，
        /// 如果创建了新的控制域，此值为true
        /// </summary>
        public bool IsNewDomain { get; private set; }

        private bool _isCanBack = false;
        /// <summary>
        /// 是否运行返回上一个界面
        /// </summary>
        public bool IsCanBack
        {
            get
            {
                return _isCanBack;
            }
            set
            {
                if (_isCanBack != value)
                {
                    _isCanBack = value;
                    RaisePropertyChanged("IsCanBack");
                }
            }
        }

        public ObservableCollection<SolutionItem> SolutionItems { get; set; }

        private View _view;
        public void Init(View view, string currentSolutionName, bool isSwitchSolution, bool isCanBack)
        {
            SolutionItems = new ObservableCollection<SolutionItem>();

            _view = view;
            EventBus.Instance.Register(this);
            EventBus.Create(CPPEI.Coolzon.ServiceProxy.ClientProxyManager.EVENTBUS_FLAGNAME).Register(this);
            NCLEventBus.Register(this);

            _preSolutionName = currentSolutionName;
            _isSwitchSolution = isSwitchSolution;
            IsCanBack = isCanBack;
        }

        #region override

        public void Active()
        {
            // 构造获取方案列表的请求
            NCLGetSolutionListEvent @event = new NCLGetSolutionListEvent();
            EventBus.Instance.PublishAsync(@event);
        }

        public void Deactive()
        {
            EventBus.Instance.Unregister(this);
            EventBus.Create(CPPEI.Coolzon.ServiceProxy.ClientProxyManager.EVENTBUS_FLAGNAME).Unregister(this);
            NCLEventBus.Unregister(this);
        }

        #endregion

        private void _ctlBtnRetry_Click(object sender, RoutedEventArgs e)
        {
            // 构造获取方案列表的请求
            NCLGetSolutionListEvent @event = new NCLGetSolutionListEvent();
            NCLEventBus.PublishAsync(@event);
        }


        public void DoActionSelectSolution(SolutionItem solutionItem)
        {
            SelectedSolutionName = solutionItem.Name;

            if (_isSwitchSolution)
            {
                // 发送切换方案事件
                CPPEI.Coolzon.Event.NCL.NCLSwitchSolutionEvent @event = new CPPEI.Coolzon.Event.NCL.NCLSwitchSolutionEvent(SelectedSolutionName);
                CPPEI.Coolzon.Event.NCL.NCLEventBus.Publish(@event);
                _view.Cancel();
            }
            else
            {
                if (!UIContext.Current.IsAutoCreateDomain)
                {
                    //SelectDomainWindows selectDomain = new SelectDomainWindows(button.Tag as SolutionItem);
                    //selectDomain.Title = solutionItem.Caption;

                    //if (selectDomain.ShowDialog().Value)
                    //{
                    //    this.Submit();
                    //}
                }
                else
                {
                    // 构造创建控制域的请求
                    CPPEI.Coolzon.Service.Contract.ReqCreateDomainData requestData = new CPPEI.Coolzon.Service.Contract.ReqCreateDomainData();
                    requestData.SolutionCaption = solutionItem.Caption;
                    requestData.SolutionName = solutionItem.Name;
                    requestData.DomainCaption = "Auto";

                    CPPEI.Coolzon.ServiceProxy.MainServiceRef.Request request = CPPEI.Coolzon.ServiceProxy.RequestUtil.BuildRequest(
                        UIContext.Current.ControlDomainId,
                        UIContext.Current.UserIdentity,
                        CPPEI.Coolzon.Service.Contract.REQUEST_SCENARIO.CONNENT,
                        CPPEI.Coolzon.Service.Contract.REQUEST_COMMAND.CONNECT.CREATEDOMAIN,
                        CPPEI.Coolzon.Service.Contract.REQUEST_MODE.SELF,
                        requestData);
                    ClientProxyManager.Instance.SendRequestSys(request);
                }
            }
        }

        [Subscribe]
        public void OnReceiveCreateDomainData(RespCreateDomainData data)
        {
            if (data != null && data.IsSuccess)
            {
                UIContext.Current.ControlDomainId = data.DomainId;
                UIContext.Current.OperatorIdentity = data.OperatorIdentity;
                this.IsNewDomain = data.IsNewDomain;

                _view.Dispatcher.Invoke(() =>
                {
                    CPPEI.Coolzon.Common.EventBus.Create(CPPEI.Coolzon.ServiceProxy.ClientProxyManager.EVENTBUS_FLAGNAME).Unregister(this);
                    _view.Submit();
                });
            }
            else if (data != null)
            {
                MessageBox.Show(data.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show("未知错误!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        public void DoActionLogout()
        {
            LogoutView logoutView = new LogoutView();
            UIContext.Current.RootViewContainer.PopView("注销", logoutView);
        }

        /// <summary>
        /// 收到来自服务器的注销结果
        /// </summary>
        /// <param name="event"></param>
        [CPPEI.Coolzon.Common.Subscribe]
        public void OnReceiveLogoutEvent(CPPEI.Coolzon.Service.Contract.RespLogoutData @event)
        {
            _view.Dispatcher.Invoke(() =>
            {
                CPPEI.Coolzon.Common.EventBus.Create(CPPEI.Coolzon.ServiceProxy.ClientProxyManager.EVENTBUS_FLAGNAME).Unregister(this);
                _view.Cancel();
            });
        }

        public  void DoActionBack()
        {
            CPPEI.Coolzon.Event.UI.UIEventBus.Publish(new UIHideSwitchSolutionViewEvent());
        }

        #region NCL Events

        [Subscribe]
        public void OnReceiveNCLGetSolutionListEvent(NCLGetSolutionListEvent @event)
        {
            if (@event.State == NCLEventState.Finished)
            {
                foreach (SolutionItem item in @event.Result.SolutionList)
                {
                    if (!string.IsNullOrWhiteSpace(_preSolutionName) && _preSolutionName.Equals(item.Name))
                    {
                        continue;
                    }
                    SolutionItems.Add(item);
                }
            }
            else if (@event.State == NCLEventState.Failure)
            {
                SolutionItems.Clear();
            }
        }
        #endregion

        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    #endregion


    [XConfigRoot("Environment")]
    public class CZEnvironment
    {
        private static Version _version;
        /// <summary>
        /// 获得主程序的版本号
        /// </summary>
        public static Version Version
        {
            get
            {
                if (_version == null)
                {
                    _version = Assembly.GetEntryAssembly().GetName().Version;
                }
                return _version;
            }
        }

        /// <summary>
        /// 版本信息-.-.-.-
        /// </summary>
        public static string Version4
        {
            get
            {
                return Version.ToString(4);
            }
        }
        /// <summary>
        /// 版本信息-.-.-
        /// </summary>
        public static string Version3
        {
            get
            {
                return Version.ToString(3);
            }
        }

        /// <summary>
        /// 版本信息-.-
        /// </summary>
        public static string Version2
        {
            get
            {
                return Version.ToString(2);
            }
        }

        private static CZEnvironment s_instance;
        public static CZEnvironment Instance
        {
            get
            {
                if (s_instance == null)
                {
                    s_instance = new CZEnvironment();
                }
                return s_instance;
            }
        }

        /// <summary>
        /// 是否显示activex组件
        /// </summary>
        [XConfig("IsShowActiveXPart", false)]
        public bool IsShowActiveXPart { get; private set; }

        /// <summary>
        /// 是否自动创建控制域
        /// </summary>
        [XConfig("IsAutoCreateDomain", true)]
        public bool IsAutoCreateDomain { get; private set; }

        /// <summary>
        /// 登录模式
        /// </summary>
        [XConfig("LoginMode", "Windows")]
        public string LoginMode { get; private set; }

        /// <summary>
        /// 是否全屏显示
        /// </summary>
        [XConfig("IsFullScreen", true)]
        public bool IsFullScreen { get; private set; }

        /// <summary>
        /// 更新服务配置
        /// </summary>
        [XConfig("UpdateServiceConfig")]
        public ServiceConfig UpdateServiceConfig { get; private set; }

        #region static methods

        public static string GetDataCacheDirectory()
        {
            return string.Format("{0}r2dc\\WEITSM\\Console\\v{1}\\Cache\\Data\\", 
                GetSystemDisk(),
                Version2);
        }

        public static string GetSettingsFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\Settings.xml"); ;
        }

        public static string GetHostConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.xml");
        }
        public static string GetSpareHostConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.spare.xml");
        }

        public static string GetPartLibConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\partlibs.xml");
        }

        /// <summary>
        /// 获取方案的存放目录地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionDirectoryPath(string solution)
        {
            return string.Format("{0}r2dc\\WEITSM\\Console\\v{1}\\Solution\\{2}\\",
                GetSystemDisk(),
                Version2,
                solution);
        }

        /// <summary>
        /// 获得方案的配置文件的地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionFilePath(string solution)
        {
            return string.Format("{0}r2dc\\WEITSM\\Console\\v{1}\\Solution\\{2}\\{2}.xml",
                GetSystemDisk(),
                Version2,
                solution);
        }

        /// <summary>
        /// 获取日志目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}r2dc\\WEITSM\\Logs\\Console\\v{1}\\",
                GetSystemDisk(),
                Version2);
        }

        /// <summary>
        /// 获得用户自己录制的按钮的配置信息文件路径
        /// </summary>
        /// <param name="userIdentity">用户编号</param>
        /// <param name="solutionName">方案名称</param>
        /// <param name="sceneName">场景名称</param>
        /// <returns></returns>
        public static string GetCustomActionFilePath(string userIdentity, string solutionName, string sceneName)
        {
            return string.Format("{0}\\Coolzon\\ConsoleApp\\v{1}\\CustomerData\\{2}\\{3}\\{4}.xml",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version3,
                userIdentity,
                solutionName,
                sceneName);

        }

        /// <summary>
        /// 是否在场景打开之后默认显示按钮面板
        /// </summary>
        /// <returns></returns>
        public static bool IsShowActionPanelWhenOpenScene()
        {
            return true;
        }

        /// <summary>
        /// 获取Environment.xml文件的地址
        /// </summary>
        /// <returns></returns>
        public static string GetEnvironmentFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\Environment.xml"); ;
        }

        /// <summary>
        /// 获取操作系统安装的磁盘目录
        /// </summary>
        /// <returns></returns>
        public static string GetSystemDisk()
        {
            string systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);
            System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(systemFolder);

            return directoryInfo.Root.ToString();
        }
        #endregion

    }
}

namespace Coolvis.UI.Theme.Display
{
}
